////////////////////////////////////////////////////////////////////////////////// // Name: FSSocket.h // TimeStamp: 1/30/02 -- 3:02pm // Author: Ken Anderson // Relation: This file so far is only related to Freespace and has no purpose for // external functions. // Purpose: Using Winsock2, this class encaspulates client functions for the system // to communicate with the server it is logged on too. Currently the system // only handles ports to mucks, this will be updated to allow all data to be // translated into this world. In addition this function will work in // combination with Freespaces World.cpp to allow viewing screens to connect // to multiple places at anytime. // // Upgrade Notes: NONE ////////////////////////////////////////////////////////////////////////////////// #ifndef _FSSocket #define _FSSocket #include #include ///////////////////////////////////////////////////////// // User defined messages for winsock applications // // Note: Activated by calls to WSAAsyncSelect // ///////////////////////////////////////////////////////// #define WS_READ (WM_USER + 1) #define WS_ACCEPT (WM_USER + 0) #define WS_CONNECT (WM_USER + 2) #define WS_CLOSE (WM_USER + 3) ///////////////////////////////////////////////////////// // Specialized flags for use in winsock class. // ///////////////////////////////////////////////////////// #define NO_FLAGS 0 ////////////////////////////////////////////////////////////////// // Different events that can be communicated between freespace // ////////////////////////////////////////////////////////////////// #define Event_Muck -1 #define MaxPacketSize 0x00FF ////////////////////////////////////////////////////////////////// // Enum of the different types of connections possible for FS // ////////////////////////////////////////////////////////////////// enum FSTYPES {MUCK, //If you are connecting to a muck SELF}; //If you are connecting to another freespace ////////////////////////////////////////////////////////////////// // This is our data buffer for sending packets of across tcp/ip // ////////////////////////////////////////////////////////////////// typedef struct _MSGHDR { BYTE IdSig; //Identity signature of msg WORD Len; //Length of message BYTE Event; //Current event } MSGHDR, *LPMSGHDR; typedef struct _MSGDATA { MSGHDR Header; BYTE Data[MaxPacketSize]; } MSGDATA, *LPMSGDATA; ///////////////////////////////////////////////////////// // Our Freespace Socket class, name shall change. // ///////////////////////////////////////////////////////// class FSSocket { public: SOCKET peer; //This is who we are connecting too FSTYPES type; //Type of system we are connecting too TCHAR* LogInBuffer; //Used on some systems to send a text stream to log in private: int status; WSADATA WSAData; //Winsock data. SOCKADDR_IN sin; //Our internet socket structure TCHAR* ipaddy; //Our addy in string form unsigned short ipport; //Our port in integer form public: FSSocket(TCHAR* addy, unsigned short port, TCHAR* LogIn, FSTYPES fstype=MUCK); FSSocket(); ~FSSocket(); BOOL WSReceive(DWORD dwSocket, LPMSGDATA msgbuf); VOID WSAccept(DWORD dwEventMsg); VOID WSSend(LPMSGDATA msgbuf); INT WSConnect(); INT WSReconnect(); VOID WSDisconnect(); VOID SetIPAddy(TCHAR* IPAddy) {ipaddy = strdup(IPAddy);} VOID SetIPPort(unsigned short IPPort) {ipport = IPPort;} TCHAR* GetIPAddy() {return ipaddy;} unsigned short GetIPPort() {return ipport;} }; #endif